home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Online / SpeakFreely / src / lpc10 / round.c < prev    next >
Text File  |  2000-05-18  |  577b  |  27 lines

  1.  
  2. /* This routine takes in a floating point number and rounds it to */
  3. /* the nearest integer.                       */
  4.  
  5. int
  6. round(afloat)
  7.   double afloat;
  8. {
  9. int rounded_int;
  10.  
  11.   /* this will truncate afloat */
  12.   rounded_int = afloat;
  13.   /* positive and negative numbers are handled differently */
  14.   if (afloat < 0) 
  15.   {
  16.     /* if the fractional part is -.5 or less round down */
  17.     if (afloat - rounded_int <= -.5) rounded_int--;
  18.   }
  19.   else
  20.   {
  21.     /* if the fractional part is .5 or greater round up */
  22.     if (afloat - rounded_int >= .5) rounded_int++;
  23.   }    
  24.     
  25.   return(rounded_int);
  26. }
  27.